package com.hzqy.persistence.dao.activity;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.hzqy.persistence.dao.core.PersistenceDao;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.activity.AnswerContentVo;
import com.hzqy.web.vo.activity.AnswerUserVo;
import com.hzqy.web.vo.activity.QuestionContentVo;

@Repository
public class ActivityAnswerDao extends PersistenceDao<PmsUserVo, Integer>{
	/**
	 * 插入用户答题对象
	 * @param answerUserVo
	 * @return 插入后的ID
	 */
	public int insertAnswerUser(AnswerUserVo answerUserVo) {
		getSqlSession().insert(this.getNamespace() +"insertAnswerUser", answerUserVo);
		int id=answerUserVo.getF_aqu_id();
		return id;
	}
	
	/**
	 * 修改用户答题对象
	 * @param answerUserVo
	 * @return
	 */
	
	public int updateAnswerUser(Map map){
		return getSqlSession().update(this.getNamespace() + "updateAnswerUser", map);
	}

	/**
	 * 题目对象查询
	 * @param questionContentVo
	 * @return
	 */
	public QuestionContentVo selectQuestionTitle(QuestionContentVo questionContentVo) {
		return getSqlSession().selectOne(this.getNamespace() + "selectQuestionTitle", questionContentVo);
	}
	
	
	/**
	 * 查询一个活动对应的题目列表
	 * @param questionContentVo
	 * @return
	 */
	public List<QuestionContentVo> selectQuestions(QuestionContentVo questionContentVo){
		return getSqlSession().selectList(this.getNamespace() + "selectQuestions", questionContentVo);
	}
	
	/**
	 * 题目对应的答案列表
	 * @param cmRecommendVo
	 * @return
	 */
	public List<AnswerContentVo> selectQuestionAnswer(int f_csac_titleid){
		return getSqlSession().selectList(this.getNamespace() + "selectQuestionAnswer", f_csac_titleid);
	}
	/**
	 * 活动题目总数
	 * @param activityid
	 * @return
	 */
	public int selectQuestionCount(String activityid) {
		return getSqlSession().selectOne(this.getNamespace() +  "selectQuestionCount", activityid);
	}
	/**
	 * 答对题数超过一定量的用户列表
	 * @param cmRecommendVo
	 * @return
	 */
	public List<AnswerUserVo> luckyAnswerUserList(Map map){
		return getSqlSession().selectList(this.getNamespace() + "luckyAnswerUserList", map);
	}
	/**
	 * 获取用户答题电话号码
	 * @param awardUserVo
	 * @return
	 */
	public String getAnswerPhone(Map map){
		String phone = "";
		try{
			phone = (String) getSqlSession().selectOne(this.getNamespace() +  "getAnswerPhone", map);
			if(phone == null || phone.trim().length() <= 0){
				phone = (String) getSqlSession().selectOne("activity-model.getIdouPhone", map);
			}
			return phone;
		}catch(Exception e){
			LOG.error("查询用户答题电话号码失败",e);
			return "";
		}
	}
	/**
	 * 查询用户答题次数(天)
	 * @param awardUserVo
	 * @return
	 */
	public int getAnswerCountDay(Map map){
		int count = 0;
		try{
			count = (Integer) getSqlSession().selectOne(this.getNamespace() + "getAnswerCountDay", map);
			return count;
		}catch(Exception e){
			LOG.error("查询用户答题次数(天)失败",e);
			return 0;
		}
	}
	/**
	 * 查询用户答题次数(周)
	 * @param awardUserVo
	 * @return
	 */
	public int getAnswerCountWeek(Map map){
		int count = 0;
		try{
			count = (Integer) getSqlSession().selectOne(this.getNamespace() +  "getAnswerCountWeek", map);
			return count;
		}catch(Exception e){
			LOG.error("查询用户答题次数(周)失败",e);
			return 0;
		}
	}
	/**
	 * 获取指定时间内的答题中奖用户人数(天)
	 * @param awardUserVo
	 * @return
	 */
	public int getAwardAnswerCountDay(Map map){
		int count = 0;
		try{
			count = (Integer) getSqlSession().selectOne(this.getNamespace() +  "getAwardAnswerCountDay", map);
			return count;
		}catch(Exception e){
			LOG.error("获取指定时间内的答题中奖用户人数(天)失败",e);
			return 0;
		}
	}
	/**
	 * 获取指定时间内的答题中奖用户人数(周)
	 * @param awardUserVo
	 * @return
	 */
	public int getAwardAnswerCountWeek(Map map){
		int count = 0;
		try{
			count = (Integer) getSqlSession().selectOne(this.getNamespace() +  "getAwardAnswerCountWeek", map);
			return count;
		}catch(Exception e){
			LOG.error("获取指定时间内的答题中奖用户人数(周)失败",e);
			return 0;
		}
	}
	
	/**
	 * 获取指定活动问题列表
	 * @param f_csqc_activityid
	 * @return
	 */
	public List<QuestionContentVo> selectQuestionList(Map<String, Object> map) {
		return getSqlSession().selectList(this.getNamespace() + "selectQuestionList",map);
	}
	
	/**
	 * 获取指定活动，内容id，类型问题列表
	 * @param f_csqc_activityid
	 * @return
	 */
	public List<QuestionContentVo> selectQuestionListOne(Map<String, Object> map) {
		return getSqlSession().selectList(this.getNamespace() + "selectQuestionListOne",map);
	}
	
}
